/**
 * Created by baidm in 2021/2/6 on 12:34
 */
/**
 * leetcode第二题：两数相加
 * input:L1=[2,4,3],L2=[5,6,4],out=[7,0,8]
 * input:L1=[0],L2=[0],out=[0]
 * input:L1=[9,9,9,9,9,9,9],L2=[9,9,9,9],out:[8,9,9,9,0,0,0,1]
 * @param l1
 * @param l2
 * @returns {Array}
 */
function sum(l1 = [], l2 = []) {
    if (!l1.length) return l2;
    if (!l2.length) return l1;
    let length = Math.max(l1.length, l2.length), s = [], t1, t2, jw = 0, ys;
    for (let i = 0; i < length; i++) {
        t1 = l1.shift() || 0;
        t2 = l2.shift() || 0;
        ys = (t1 + t2 + jw) % 10;
        jw = Math.floor((t1 + t2 + jw) / 10);
        s.push(ys);
    }
    ys && s.push(ys);
    return s;
}